# -*- coding: utf-8 -*-
import logging
import os
import requests


class Helper:
    def __init__(self):
        pass

    # 端口占用清理
    @staticmethod
    def killPort(port):
        # # 查找端口的pid
        find_port = 'netstat -aon | findstr %s' % port
        result = os.popen(find_port)
        text = result.read()
        logging.info('清理占用端口>>>' + find_port)
        logging.info('清理占用端口>>>' + text)
        # logging.info(text [9:23])
        if text[9:23] == '127.0.0.1:%s' % port:
            pid = text[70:76]
            logging.info('占用端口的pid:' + pid)
            find_kill = 'taskkill -f -pid %s' % pid
            result = os.popen(find_kill)
            logging.info(result.read())
            pass

    # Post请求
    @staticmethod
    def httpPost(url, parameter={}):
        return requests.post(url, params=parameter)
